<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            margin: 100px auto;
            width: 500px;
            border-collapse: collapse;
            text-align: center;
        }
        
        td,
        th {
            border: 1px solid #333;
        }
        
        thead tr {
            height: 40px;
            background-color: #ccc;
        }
    </style>
</head>

<body>
    <table>
        <thead cellspacing="0">
            <tr>
                <th>姓名</th>
                <th>科目</th>
                <th>成绩</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>

        </tbody>

        <script>
            // 创建数据 以对象数组的形式生成
            var datas = [{
                name: '张三',
                subject: 'JavaScript',
                score: 100
            }, {
                name: '张四',
                subject: 'JavaScript',
                score: 90
            }, {
                name: '张五',
                subject: 'JavaScript',
                score: 85
            }, {
                name: '张六',
                subject: 'JavaScript',
                score: 73
            }];
            var tbody = document.querySelector('tbody');
            for (let i = 0; i < datas.length; i++) {
                // 向tbody里添加tr
                // 创建tr
                var tr = document.createElement('tr');
                tbody.appendChild(tr);
                // tr内添加td td数量取决于对象内属性个数
                for (var k in datas[i]) {
                    // 创建td
                    var td = document.createElement('td');
                    td.innerHTML = datas[i][k];
                    tr.appendChild(td);
                }
                // 创建删除单元格
                var td = document.createElement('td');
                td.innerHTML = '<a href="javascript:;">删除</a>';
                tr.appendChild(td);
            }
            // 添加删除的点击事件
            var as = document.querySelectorAll('a');
            for (let i = 0; i < as.length; i++) {
                as[i].onclick = function() {
                    // 点击a删除当前a所在的行
                    tbody.removeChild(this.parentNode.parentNode);
                }
            }
        </script>
    </table>
</body>

</html>